package com.woniu.supermarket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.FinancialDetail;
import com.woniu.supermarket.mapper.CollectionSummaryMapper;
import com.woniu.supermarket.mapper.FinancialDetailMapper;
import com.woniu.supermarket.mapper.RefundSummaryMapper;
import com.woniu.supermarket.service.IFinancialDetailService;
import com.woniu.supermarket.vo.CollectionSummaryVo;
import com.woniu.supermarket.vo.RefundSummaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class FinancialDetailServiceImpl implements IFinancialDetailService {
    @Autowired
    FinancialDetailMapper financialDetailMapper;
    @Autowired
    CollectionSummaryMapper collectionSummaryMapper;
    @Autowired
    RefundSummaryMapper refundSummaryMapper;


    @Override
    public PageInfo<FinancialDetail> findByConds(Integer now, Integer size, String number) {
        PageHelper.startPage(now,size);
        List<FinancialDetail> lists = financialDetailMapper.selectAll(number);
        return new PageInfo<>(lists);
    }

    @Override
    public PageInfo<CollectionSummaryVo> findCollectionSummaryVoByConds(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<CollectionSummaryVo> lists = collectionSummaryMapper.selectAllByDay();
        for(CollectionSummaryVo p:lists){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();
            int day = p.getDay();
            p.setTime(year+"-"+month+"-"+day);
        }
        return new PageInfo<>(lists);
    }

    @Override
    public PageInfo<CollectionSummaryVo> findCollectionSummaryVoByMonthByConds(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<CollectionSummaryVo> lists = collectionSummaryMapper.selectAllByMonth();
        for(CollectionSummaryVo p:lists){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();

            p.setTime(year+"-"+month);
        }
        return new PageInfo<>(lists);
    }

    @Override
    public PageInfo<CollectionSummaryVo> findCollectionSummaryVoByYearByConds(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<CollectionSummaryVo> lists = collectionSummaryMapper.selectAllByYear();
        for(CollectionSummaryVo p:lists){
            //生成属性time
            int year = p.getYear();
            p.setTime(String.valueOf(year));
        }
        return new PageInfo<>(lists);
    }

    @Override
    public PageInfo<RefundSummaryVo> findRefundSummaryVoByYearByConds(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<RefundSummaryVo> lists = refundSummaryMapper.selectAllByYear();
        for(RefundSummaryVo p:lists){
            //生成属性time
            int year = p.getYear();
            p.setTime(String.valueOf(year));
        }
        return new PageInfo<>(lists);
    }

    @Override
    public PageInfo<RefundSummaryVo> findRefundSummaryVoByMonthByConds(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<RefundSummaryVo> lists = refundSummaryMapper.selectAllByMonth();
        for(RefundSummaryVo p:lists){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();

            p.setTime(year+"-"+month);
        }
        return new PageInfo<>(lists);
    }

    @Override
    public PageInfo<RefundSummaryVo> findRefundSummaryVoByConds(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<RefundSummaryVo> lists = refundSummaryMapper.selectAllByDay();
        for(RefundSummaryVo p:lists){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();
            int day = p.getDay();
            p.setTime(year+"-"+month+"-"+day);
        }
        return new PageInfo<>(lists);
    }

    @Override
    public List<CollectionSummaryVo> findAllCollectionSummaryVoByDay() {
        List<CollectionSummaryVo> list = collectionSummaryMapper.selectAllByDay();
        for(CollectionSummaryVo p:list){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();
            int day = p.getDay();
            p.setTime(year+"-"+month+"-"+day);
        };
        return list;
    }

    @Override
    public List<CollectionSummaryVo> findAllCollectionSummaryVoByMonth() {
        List<CollectionSummaryVo> list = collectionSummaryMapper.selectAllByMonth();
        for(CollectionSummaryVo p:list){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();
            p.setTime(year+"-"+month);
        };
        return list;
    }

    @Override
    public List<CollectionSummaryVo> findAllCollectionSummaryVoByYear() {
        List<CollectionSummaryVo> list = collectionSummaryMapper.selectAllByYear();
        for(CollectionSummaryVo p:list){
            //生成属性time
            int year = p.getYear();
            p.setTime(year+"");
        };
        return list;
    }

    @Override
    public List<RefundSummaryVo> findAllRefundSummaryByDay() {
        List<RefundSummaryVo> list = refundSummaryMapper.selectAllByDay();
        for(RefundSummaryVo p:list){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();
            int day = p.getDay();
            p.setTime(year+"-"+month+"-"+day);
        };
        return list;
    }

    @Override
    public List<RefundSummaryVo> findAllRefundSummaryByMonth() {
        List<RefundSummaryVo> list = refundSummaryMapper.selectAllByMonth();
        for(RefundSummaryVo p:list){
            //生成属性time
            int year = p.getYear();
            int month = p.getMonth();
            p.setTime(year+"-"+month);
        };
        return list;
    }

    @Override
    public List<RefundSummaryVo> findAllRefundSummaryByYear() {
        List<RefundSummaryVo> list = refundSummaryMapper.selectAllByYear();
        for(RefundSummaryVo p:list){
            //生成属性time
            int year = p.getYear();
            p.setTime(year+"");
        };
        return list;
    }
}
